#include "Timer.h"
#include <iostream>

#include <GL/glew.h>
#include <GL/glut.h>

void Timer::beginFrame() {
	t1 = glutGet(GLUT_ELAPSED_TIME);
	frameCount++;
}

void Timer::endFrame() {
	t2 = glutGet(GLUT_ELAPSED_TIME);
	totalElapsedTime += t2-t1;
}

Timer::Timer() {
	frameCount = 0;
	frameRefCount = 50;
	totalElapsedTime = 0.0;
}

float Timer::getFPS() {
	float fps = frameCount / ((float)totalElapsedTime / 1000.0f);

	frameCount = 0;
	totalElapsedTime = 0;

	return fps;
}

bool Timer::isTimeToUpdate() {
	return frameCount && frameCount > frameRefCount;
}
